package com.yaorange.jk.web.cargo;

import com.opensymphony.xwork2.ModelDriven;
import com.yaorange.jk.entity.Contract;
import com.yaorange.jk.service.ContractService;
import com.yaorange.jk.utils.Pagination;
import com.yaorange.jk.web.BaseAction;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author coach tam
 * @date 2017/11/1
 */
public class ContractAction extends BaseAction implements ModelDriven<Contract> {


    private Contract model = new Contract();

    //分页对象
    private Pagination page = new Pagination();

    //列表
    private List<Contract> contractList;


    @Autowired
    private ContractService contractService;

    /**
     * 分页查询
     */
    public String list() {
        page = contractService.findPage(page.getPageNo(), page.getPageSize(),0);
        page.setUrl("contractAction_list");
        push(page);
        return "list";
    }

    /**
     * 跳转添加页面
     */
    public String tocreate() {

        contractList = contractService.findAll();
        return "tocreate";
    }

    /**
     * 添加
     */
    public String insert() {
        contractService.save(model);
        return "rlist";
    }

    /**
     * 跳转更新页面
     * @return
     */
    public String toupdate() {
        //根据id查询部门老数据
        model = contractService.findById(model.getId());
        //存入栈顶
        push(model);

        return "toupdate";
    }

    /**
     *更新
     */
    public String update() {
        contractService.update(model);
        return "rlist";
    }

    /**
     * 批量删除
     */
    public String delete() {
        String[] ids = model.getId().split(", ");
        contractService.deleteByIds(ids);
        return "rlist";
    }

    public String toview(){
        model = contractService.findById(model.getId());
        push(model);
        return "toview";
    }


    public String  submit(){
        String[] ids = model.getId().split(", ");
        contractService.submitByIds(ids);
        return "rlist";
    }



    public void setPage(Pagination page) {
        this.page = page;
    }

    public List<Contract> getContractList() {
        return contractList;
    }

    @Override
    public Contract getModel() {
        return model;
    }


}
